<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">菜单名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" th:value="${menu.name}" maxlength="50" lay-verify="required" lay-reqtext="菜单名称不能为空" placeholder="请输入菜单名称" value="" class="layui-input">
<!--            <tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>

    <input type="hidden" name="id" th:value="${menu.id}">

    <div class="layui-form-item">
        <label class="layui-form-label required">菜单编码</label>
        <div class="layui-input-block">
            <input type="text" name="code" th:value="${menu.code}" maxlength="50" lay-verify="required" lay-reqtext="菜单编码不能为空" placeholder="请输入教室编号" value="" class="layui-input">
            <!--            <tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label ">选择上级菜单编码</label>
        <div class="layui-input-block">
            <select name="parentCode">
                <option value="">请选择上级菜单</option>
                <option th:each="pmenu,menuStart:${parentMenus}" th:value="${pmenu.code}" th:text="${pmenu.name}" th:selected="${pmenu.code==menu.parentCode}"></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label ">菜单请求地址</label>
        <div class="layui-input-block">
            <input type="text" name="url" th:value="${menu.url}" maxlength="200"  lay-reqtext="菜单请求地址不能为空" placeholder="请输入菜单请求地址" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">排序</label>
        <div class="layui-input-block">
            <input type="number" name="sort" th:value="${menu.sort}" maxlength="2" lay-verify="required" lay-reqtext="排序不能为空" placeholder="请输入排序" value="" class="layui-input">
            <!--            <tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">是否启用</label>
        <div class="layui-input-block">
            <input type="radio" name="isUse" value="1" title="启用" th:checked="${menu.isUse}">
            <input type="radio" name="isUse" value="0" title="未启用" th:checked="${!menu.isUse}">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>

</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            //异步保存数据
            $.ajax({
                type: 'post',
                url: '/back/menu/edit',
                dataType: 'json',
                data: data.field,
                success: function (ret) {
                    if (ret.code == 0) {//编辑成功
                        layer.msg(ret.msg, function () {
                            // console.log('hello')
                            //刷新表单数据
                            parent.layui.treeTable.reload('tree-table')
                            // 关闭弹出层
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        })
                    } else {//编辑失败
                        layer.msg(ret.msg);
                    }
                }
            });
            return false;
        });

    });
</script>
</body>
</html>